import request from '@/utils/request';
import type { CategoryResponseData, AttrResponseData, Attr } from './type';

enum API {
  //获取一级分类的接口地址
  C1_URL = '/admin/product/getCategory1',
  //获取二级分类的接口地址
  C2_URL = '/admin/product/getCategory2/',
  //获取三级分类的接口地址
  C3_URL = '/admin/product/getCategory3/',
  //获取商品基础属性接口
  ATTR_URL = '/admin/product/attrInfoList',
  //添加或者修改接口
  ADDORUPDATEATTR_URL = '/admin/product/saveAttrInfo',
  //删除已有的属性
  DELETEATTR_URL = '/admin/product/deleteAttr/',
}

/**
 *
 *  查询C1属性列表
 */
export function reqC1() {
  return request<any, any>({
    url: API.C1_URL,
    method: 'get',
  });
}

/**
 *
 *  查询C2属性列表
 * @param category1Id c1属性id
 */
export function reqC2(category1Id: number | string) {
  return request<any, CategoryResponseData>({
    url: API.C2_URL + category1Id,
    method: 'get',
  });
}

/**
 *
 *  查询C3属性列表
 * @param category2Id c2属性id
 */
export function reqC3(category2Id: number | string) {
  return request<any, CategoryResponseData>({
    url: API.C3_URL + category2Id,
    method: 'get',
  });
}

/**
 *
 *  获取对应分类下已有的属性和属性值接口
 * @param category1Id c1属性id
 * @param category2Id c2属性id
 * @param category3Id c3属性id
 */
export function reqAttr(category1Id: number | string, category2Id: number | string, category3Id: number | string) {
  return request<any, AttrResponseData>({
    url: `${API.ATTR_URL}/${category1Id}/${category2Id}/${category3Id}`,
    method: 'get',
  });
}

/**
 *
 *  新增或者修改属性
 * @param data 属性与属性值对象，详细参数参考类型定义Attr
 */
export function reqAddOrUpdateAttr(data: Attr) {
  return request<any, any>({
    url: API.ADDORUPDATEATTR_URL,
    method: 'post',
    data,
  });
}

/**
 *
 *  删除属性
 * @param data 属性与属性值对象，详细参数参考类型定义Attr
 */
export function reqRemoveAttr(attrId: number) {
  return request<any, any>({
    url: API.DELETEATTR_URL + attrId,
    method: 'delete',
  });
}
